package edu.zut.cn.domain;


import edu.zut.cn.enums.CodeEnum;
import lombok.Data;

/**
 * ResponseResult返回
 *
 * @author 张小訫
 */
@Data
public class ResponseResult<T> {
    private Integer code;
    private String message;
    private Long count;
    private T data;

    private ResponseResult(){}

    private ResponseResult(Integer code, String message, Long count, T data) {
        this.code = code;
        this.message = message;
        this.count = count;
        this.data = data;
    }

    public static ResponseResult success(){
        return new ResponseResult(CodeEnum.SUCCESS.getCode(),CodeEnum.SUCCESS.getMsg(),null,null);
    }

    public static ResponseResult success(CodeEnum codeEnum){
        return new ResponseResult(codeEnum.getCode(),codeEnum.getMsg(),null,null);
    }

    public static ResponseResult success(int code,String message){
        return new ResponseResult(code,message,null,null);
    }

    public static ResponseResult success(CodeEnum codeEnum,Object data){
        return new ResponseResult(codeEnum.getCode(),codeEnum.getMsg(),null,data);
    }

    public static ResponseResult success(CodeEnum codeEnum,Long count, Object data){
        return new ResponseResult(codeEnum.getCode(),codeEnum.getMsg(),count,data);
    }

    public static ResponseResult fail(){
        return new ResponseResult();
    }

    public static ResponseResult fail(CodeEnum codeEnum){
        return new ResponseResult(codeEnum.getCode(),codeEnum.getMsg(),null,null);
    }

    public static ResponseResult fail(int code,String message){
        return new ResponseResult(code,message,null,null);
    }

    public static ResponseResult fail(CodeEnum codeEnum,Object data){
        return new ResponseResult(codeEnum.getCode(),codeEnum.getMsg(),null,data);
    }

    public static ResponseResult fail(CodeEnum codeEnum,Long count, Object data){
        return new ResponseResult(codeEnum.getCode(),codeEnum.getMsg(),count,data);
    }
}
